<?php 

class ArrowTagContainer extends ArrowNode{
	
	private $keepContentCode = false;
	private $contentCode = false;
	private $parseContentCode = false;


	public function isContentCodeKept(){
		return $this->keepContentCode;
	}
	public function setContentCodeKept($keep){
		$this->keepContentCode = $keep;
	}
	
	public function setParseContent( $set ){
		$this->parseContentCode = $set;
	}
	
	public function setContentCode( $contentCode ){
		$this->contentCode = $contentCode;
	}
	public function getContentCode(){
		return $this->contentCode;
	}
	
	/*public function getInitInstructions(){

	}*/
	
	
	public function getPreInitInstructions(){

		
		$code = "";
		if($this->isContentCodeKept()  ){
			$contentCode = $this->getContentCode();
			if(!empty($contentCode) ){
				
				
				
				if($this->parseContentCode){
					
						
					$code.='$parser = ArrowTemplateParser::getDefault();'."\n";
					$parser = new ArrowTemplateParser();	
					 $parser->parseString($contentCode, $this, false);
					$contentCode = $parser->getParsedCode();			
					$code.='$code = base64_decode("'.base64_encode($contentCode).'");'."\n";
					$code.= '$arrowTag'.$this->getNodeIndex().'->setContentCode(  $code );'."\n";
				}else{
					$code.='$code = base64_decode("'.base64_encode(str_replace("_arrow_end_delim_", "?>",$contentCode)).'");'."\n";
					$code.='$arrowTag'.$this->getNodeIndex().'->setContentCode( $code );'."\n";
				}
			}			
		}
		
		return $code;
	}
	
	public function generateBlockStartCode(){
		//$code = '{if isset($arrowTag'.$this->getNodeIndex().')}';
		$code = '{if $arrowTag'.$this->getNodeIndex().'->isDisplayed()}';
		$code.= '{$arrowTag'.$this->getNodeIndex().'->generateBlockStart()}';
		$code.= '{capture assign="arrowTag'.$this->getNodeIndex().'Content"}';
		return $code;
	}
	
	public function generateBlockEndCode(){
		
		$code = '{/capture}';
		$code.= '{$arrowTag'.$this->getNodeIndex().'->generateBlockContent($arrowTag'.$this->getNodeIndex().'Content)}';
		$code.= '{$arrowTag'.$this->getNodeIndex().'->generateBlockEnd()}{/if}';//{/if};
		return $code;
	}
	
	
	public function generateBlockStart(){
		if(!$this->isDisplayed()) return "";
		return "arrow-block-start( ".$this." )";
	}
	
	public function generateBlockContent( $contentIn ){
		if($this->isDisabled()) return "";
		return $contentIn;
	}
	
	public function generateBlockEnd(){
		if(!$this->isDisplayed()) return "";
		return "arrow-block-end( ".$this." )";
	}
	
	public function generate(){
		if(!$this->isDisplayed()) return "";
		return $this->generateBlockStart().$this->generateBlockEnd();	
	}
	public function generateOutputCode(){
		return $this->generateBlockStartCode().$this->generateBlockEndCode();
	}
}

?>